#pragma once

#include "ofMain.h"

/** A base class for a physics-enabled particle with a finite life.  **/
class Particle
{
protected:
    float t_created; /**< Time the particle was created **/
    float t_elapsed; /**< Time elapsed since the particle was created **/

    /** Updates position and determines if particle has died.
        \return true if particle has died. false otherwise. **/
    bool positionAndTtlUpdate();

public:
    /** Constructor. 
        \param loc Initial location of particle in world coordinates
        \param vel Initial velocity of particle in world coordinates
        \param ttl Amount of time the particle has to live **/
    Particle(ofPoint loc, ofPoint vel, float ttl = 1.5f);

    /** Sets the color of the particle to a hex integer in 0xRRGGBB format.
        \param color Color to set the particle to in 0xRRGGBB format **/
    void setColor(int color);
    /** Sets the color of the particle to the R, G, and B components given in range of 0-255
        \param r Red component (0-255)
        \param g Green component (0-255)
        \param b Blue component (0-255) **/
    void setColor(int r, int g, int b);

    /** Updates particle and performs all math and computationally intensive tasks.
        \return true if particle has died **/
    virtual bool update();
    /** Draws the particle in the world. **/
    virtual void draw();

    ofPoint loc,   /**< Location of the particle **/
            vel;   /**< Velocity of the particle **/
    ofColor color; /**< Color of the particle **/

    const float ttl; /**< Particle's time to live **/
};
